﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ByrooPiirang", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(ByrooPiirang))]
    public class ByrooPiirangSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IByrooPiirang clazz;
        
        public ByrooPiirangSerializer(IByrooPiirang clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.AsjaLiikKL!=null) {
                Writer.WriteStartElement("AsjaLiikKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.AsjaLiikKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaliseAsjadeKuvamineKL!=null) {
                Writer.WriteStartElement("OsaliseAsjadeKuvamineKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.OsaliseAsjadeKuvamineKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaNR!=null) {
                Writer.WriteStartElement("AsjaNR");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.AsjaNR.Count);
                for (int x = 0; ((clazz.AsjaNR != null) 
                            && (x < clazz.AsjaNR.Count)); x = (x + 1)) {
                    if (clazz.AsjaNR[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsjaNR[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="AsjaLiikKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaLiikKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("AsjaLiikKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="OsaliseAsjadeKuvamineKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OsaliseAsjadeKuvamineKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("OsaliseAsjadeKuvamineKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaNR") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaNR = new System.Collections.Generic.List<System.String>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("AsjaNR");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                clazz.AsjaNR.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                            }
                            else {
                                clazz.AsjaNR.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
